OB.Emes_ActionButton = OB.Emes_ActionButton || {};


//外协计划审核
OB.Emes_ActionButton.PlanToExamine  = function(params, view) {
	var view = view.activeView.viewGrid;
	var records = view.getSelectedRecords();
	var length = records.getLength();
	if (length) {
		isc.confirm("确定审核通过？", function(ok) {
			if (ok) {
				// 选择纪录行
				var selectRecords = [];
				for ( var i = 0; i < length; i++) {
					selectRecords.push(records[i].id);
				}
				OB.RemoteCallManager.call(
					"com.mes.handler.PlanToExamineHandler", {
						ids : selectRecords.join("#####")
					}, {}, function(request, data, response) {
						if (data.flag) {
							view.refreshGrid();
							isc.showMessage(data.message);
						} else {
							isc.showMessage(data.message);
						}
					}
				);
			}
		});
	} else {
		isc.showMessage("请选择纪录！");
	}
}

//销售订单（B端）调用存储过程下发为计划订单
OB.Emes_ActionButton.PlanOrderCall  = function(params, view) {
    var view = view.activeView.viewGrid;
    var records = view.getSelectedRecords();
    var length = records.getLength();
    if (length) {
        isc.confirm("确定下发？", function(ok) {
            if (ok) {
                // 选择纪录行
                var selectRecords = [];
                for ( var i = 0; i < length; i++) {
                    selectRecords.push(records[i].id);
                }
                OB.RemoteCallManager.call(
                    "com.mes.handler.plan.PlanOrderCallHandler", {
                        ids : selectRecords.join("#####")
                    }, {}, function(request, data, response) {
                        if (data.flag) {
                            view.refreshGrid();
                            isc.showMessage(data.message);
                        } else {
                            isc.showMessage(data.message);
                        }
                    }
                );
            }
        });
    } else {
        isc.showMessage("请选择纪录！");
    }
}

//外协计划数量修改操作 取消按钮
OB.Emes_ActionButton.MaterialImport  = function(params, view) { 
	var view = view.activeView.viewGrid;
	var records = view.getSelectedRecords();
	var length = records.getLength();
	if (length) {
		isc.confirm("确定取消外协计划？", function(ok) {
			if (ok) {
				// 选择纪录行
				var selectRecords = [];
				for ( var i = 0; i < length; i++) {
					selectRecords.push(records[i].id);
				}
				OB.RemoteCallManager.call(
						"com.mes.handler.MaterialImportHandler", {
							ids : selectRecords.join("#####")
						}, {}, function(request, data, response) {
							if (data.flag) {
								view.refreshGrid();
								isc.showMessage(data.message);
							} else {
								isc.showMessage(data.message);
							}
						});
			}
		});
	} else {
		isc.showMessage("请选择纪录！");
	}
}


//质检二次判定 不合格产品 再次判定按钮
OB.Emes_ActionButton.qualityExamine  = function(params, view) { 
	var view = view.activeView.viewGrid;
	var records = view.getSelectedRecords();
	var length = records.getLength();
	if (length) {
		isc.confirm("确定完工报检？", function(ok) {
			if (ok) {
				// 选择纪录行
				var selectRecords = [];
				for ( var i = 0; i < length; i++) {
					selectRecords.push(records[i].id);
				}
				OB.RemoteCallManager.call(
						"com.mes.handler.QualityExamineHandler", {
							ids : selectRecords.join("#####")
						}, {}, function(request, data, response) {
							if (data.flag) {
								view.refreshGrid();
								isc.showMessage(data.message);
							} else {
								isc.showMessage(data.message);
							}
						});
			}
		});
	} else {
		isc.showMessage("请选择纪录！");
	}
}

